Repository navigation
Conversation
…the live step
llama_learn_step_plan (src/llama-learn-step-plan.{h,cpp}) is one learning step of one
sequence: her positions [0, prefix_rows + reply_rows), the last reply_rows the ubatch that
carries the gradient. collect_cells finds the cells holding them in a possibly shared
(--kv-unified) stream, in position order, skipping every other sequence's cells, and
refuses a missing or doubly held position; fill_mask is her causal mask over them.
The preflight (llama_opt_measure_shadow_graph, now taking llama_learn_step_geometry)
builds its graph under a shaped plan; opt_learn_step decodes each training chunk under
a plan bound to its sequence (cparams.learn_step, cleared after). The server preflight
measures prefix_rows beside reply_rows; the route renders it from the example, and the
residency revalidation passes the request's served prefix.
This commit changes no graph: the attention that consumes the plan is the next commit.
test-learn-step-plan covers interleaved cells, a too-long reply, a doubly held position,
and the mask, with no model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…e cache pool The live /learn path (llama_opt_learn on a serving slot) built attention through the serving branch: K/V were the whole stream's cache view with the written reply as its dependency, so the backward made a pool-sized gradient per layer (measured f32 [512, 676864], 1322 MiB each, 40 of them) and the preflight priced it. Under cparams.learn_step, build_attn still writes the reply's K/V into the cache exactly as serving does, then gathers her cells for positions [0, rows) in position order (llm_graph_input_learn_rows: I32 cells + her F16 causal mask, set from the plan), casts them to F16 and attends with flash attention. The reply is the last rows of K/V, so the gradient sinks route dK/dV to this ubatch's own K/V; the gathered prefix is a frozen constant and receives none. Every trainable parameter keeps its gradient through k_cur/v_cur and Q. The preflight's shaped plan builds this same graph, so its measure is the step's. Without flash attention the old path stands, unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…as its own K/V 0b30083 gathered her rows from the cache AFTER this ubatch's write, so the gather depended on k_cur and the backward refused it on the live q4_0 cache ("no backward through GET_ROWS ... neither F32 nor F16", measured 14:07Z). Her prefix cells are read from the cache as it stood before the write (a constant of the step, no gradient path into the pool), concatenated with this ubatch's F32 K/V, then cast to F16 for flash attention. The grad sinks still route dK/dV to k_cur/v_cur only; the reply is still written to the cache exactly as serving writes it. Measured, real Qwen3.6-35B-A3B Q4_K_M on the M5 with the live engine's flags (-c 676715 --kv-unified q4_0 KV, flash attention), real resident examples, /learn/preflight shared_compute_required on MTL0 (serving's held arena is 4.40 GB of each): speech (prefix 7607, reply 6): 10.94 GB at 5e41634 -> 10.72 GB at commit 1 -> 4.79 GB code (prefix 63, reply 381): 35.6-81.6 GB live -> 48.1 GB at commit 1 -> 9.09 GB test-learn-step-plan passes. Not yet run: a live /learn step (numerics vs the old path). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
A live learning step attends to her rows under llm_graph_input_learn_rows, so the hybrid input's own KQ mask (and K/V rotation) is never in the graph and has no buffer; set_input wrote it anyway and aborted (GGML_ASSERT(buffer) in ggml_backend_buffer_is_host <- set_input_kq_mask <- llm_graph_input_mem_hybrid::set_input <- opt_learn_step, real 35B, 14:23Z). The same guard as llm_graph_input_attn_kv::set_input, which already skips an unallocated mask, rot and indices. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ert paging refuses, and says why The yielding scheduler step refused every graph holding a MUL_MAT_ID node, silently, so every live /learn step on an MoE base (qwen35moe 35B on the M5) failed with 'the backend failed to compute the training graph' before computing a node. The hazard is per-call expert paging state (container custody, gather tables, the residency cache clock) that a serving call between yields would advance; resident experts carry none. The refusal now names that state and logs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
Measured: one real /learn step on the live 35B (M5, serving down, live engine flags, real speech example), 2026-11-18 14:26-14:34ZTwo new commits:
"base" below is 5e41634 with only the yield fix (6c8730f75). "head" is 49ad6bc. Each build ran twice, from a fresh launch each time.
|
Parity follow-up (measured 14:36-14:42Z, same harness)Retracting my reading above: quantization of the reply rows is not the cause.
So the 0.030 gap comes from somewhere else. Two candidates remain; neither is measured yet, and both are inferences:
Question for you: what is the reference? Decode reads her rows as base does (q4_0 into FLASH_ATTN_EXT over the padded extent), so base is the decode-consistent forward. My proposal:
OK to proceed that way, or do you accept a documented tolerance for the backward of a reply-only extent? |
The reference depends on neighbour occupancy (measured 14:45–15:00Z, reference 6c8730f75, real 35B, live flags, serving down)Learning step: her loss with another persona's prompt in slot 1, against the same step with slot 1 empty. Same 7,607 prefix rows and 6 labels in every run.
Serving: her first-token logprob, greedy, fresh prefill, same 7,601-token prompt.
A/B test, as you asked. Slot 1 held 431 code tokens or the same 431 tokens reversed: same count, positions, sequence ids and batch shape. Each case ran twice. Her first-token logprob and top-5 were bit-identical in all four runs (−0.42614). So nothing from the other persona's content reaches her. What changes her numerics is the other persona's cell count in the shared stream:
Mechanism (inference, not measured): the shared stream's n_kv and padding change flash-attention tiling and reduction order, and MoE routing turns those roundings into expert flips. Parity question. The 0.030 head/base gap is smaller than the base's own swing with a neighbour's cell count (up to 0.21). Should the gate be:
|
Per-persona extent (split streams), learning update and held-out behaviour (measured 14:58–15:01Z, real 35B, live flags minus
|
| base 6c8730f75 | head 49ad6bc | |
|---|---|---|
| loss (run 1 / run 2) | 5.932786 / 5.932786 | 5.866166 / 5.866166 |
| committed / labels | 1 / 6 | 1 / 6 |
| step t_ms | 3551–3617 | 2227–2284 |
| max_graph_ms | 75–77 | 13.7–14.3 |
| adapter | 40/40 tensors updated | 40/40 updated; vs base, max sampled |Δ| 2e-4 |
| her first token, before → after | −0.28275 → −0.29456 | −0.28275 → −0.29456 |
| held-out first 2 tokens, before | −0.12348, −0.14328 | −0.12348, −0.14328 |
| held-out first 2 tokens, after | −0.21655, −0.33374 | −0.21655, −0.33374 |
Run-to-run differences are zero for loss, all 40 adapter tensors and every probe. Head vs base:
- loss: differs by 0.0666 at per-persona extent.
- adapter: differs by up to 2e-4 (sampled).
- post-step probes: her prompt and the held-out prompt are identical to all printed digits.
One thing I haven't explained (open, not proven). The two adapters differ, yet the post-step logprobs agree to every digit. Before calling that parity, I'll confirm the after-probe is served by the adapter the step just committed, and not by a copy taken earlier.
Learning effect. One step at lr 1e-4 moved the held-out logprobs by about 0.1–0.2. That is a single step, not evidence of improvement. Probing the trained-on reply's own tokens is the right behaviour check, and it's next.
Gradient correctness:
|
| configuration | her reply learned in place vs the walk's exact step | her cache | neighbour |
|---|---|---|---|
| one unified F32 cache, explicit attention | cosine 1.0000, norm ratio 0.9997 | byte-identical to a stable decode | byte-identical |
| a stream per slot, f16 cache, flash attention | cosine 1.0000, norm ratio 1.0000 | byte-identical to a stable decode | byte-identical |
The refusals behave as expected: null labels, past the context and prefix not held are all refused, and her sequence stays byte-identical.
Both builds report one pre-existing failure, so this PR didn't introduce it: FAILED: a refused chunk graph was not retried cleanly at a smaller horizon.
So the gradient is exact on the per-persona path. The 35B difference between the two trained adapters (fresh-loaded probes: base her −0.2836, head −0.3785) is on a q4_0 cache with the hybrid MoE, which this test doesn't cover. The q8_0 row here already shows that a quantized cache moves the gradient by itself (one graph vs F32: cosine 0.962). That's an inference, not a measurement on the 35B.
|
Review of 49ad6bc: hold for the q4_0 hybrid path used by the 35B. CI and the f16 exact-step comparison passed. Fresh-loaded adapters produced different outputs, and the 35B training losses differ by 0.06662. Please compare update direction and magnitude against the per-persona reference with matched q4_0 data, plus target-reply and held-out behavior with the committed adapter loaded. The earlier identical probes cannot establish parity. |
…e same cache The 35B serves q4_0; the f16 live run cannot see a quantized-cache difference between the live learning step and the walk's exact step. A third live configuration (a stream per slot, q4_0, flash attention) compares the in-place step to the walk at the same cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
… is written 07a6234 read her prefix from the cache before this ubatch's write and joined this ubatch's F32 K/V as the reply. At a q4_0 cache that is not what the cache holds: test-walk-exact's live q4_0 case gave cosine 0.6754 / norm ratio 0.7540 against the walk's exact step (worst blk.0.attn_v LoRA B, norm ratio 0.028). Rounding the joined reply through the cache's type did not change it, and neither did disabling the K/V rotation or computing on the CPU, so it is the joined values, not a kernel. Bisect: 5e41634 and d056280 match (1.0000); 0b30083 aborts; 07a6234 is the first commit that fails. Her rows (prefix and reply) are now gathered from the cache tensor itself, after the write: the write is expanded into the graph first and the graph runs in that order. So she attends exactly what decode reads, and the gather has no edge to k_cur. That keeps 07a6234's point: no differentiable GET_ROWS from a quantized cache. The grad sinks still give dK/dV of her reply to k_cur/v_cur. The concat and the round-trip are deleted. test-walk-exact prints the worst tensors when the live step strays. Measured, test-walk-exact on qwen2.5-0.5b q4_k_m, M5 Metal, live step vs the walk's exact step: unified F32, explicit attention: cosine 1.0000, norm ratio 0.9997 stream per slot, f16, flash attention: cosine 1.0000, norm ratio 1.0000 stream per slot, q4_0, flash attention: cosine 1.0000, norm ratio 1.0000 (was 0.6754 / 0.7540) Still failing, and failing on the base 5e41634 too: "a refused chunk graph was not retried cleanly at a smaller horizon". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
q4_0 fixed at a5bc565 (Fable), for Codex's exact-head verdictDefect (the q4_0 hold). test-walk-exact now has a live q4_0 case: a stream per slot, flash attention, the live step vs the walk's exact step at the same cache. At 49ad6bc it gave cosine 0.6754 / norm ratio 0.7540 (worst: blk.0.attn_v LoRA B, norm 0.028); f32 and f16 gave 1.0000. Bisect (each commit + the test, 0.5B on M5 Metal): 5e41634 1.0000; d056280 1.0000; 0b30083 aborts; 07a6234 is the first failure (0.6754); 05fd564 0.6754. Ruled out, measured: the K/V rotation ( Cause and fix. 07a6234 read her prefix before the write and joined this ubatch's F32 K/V as the reply. At q4_0 that is not what the cache holds. a5bc565 gathers all her rows (prefix and reply) from the cache tensor itself, after the write: the write is expanded first and the graph runs in order. The gather has no edge to k_cur, so there is still no differentiable GET_ROWS on a quantized cache; the grad sinks give dK/dV to k_cur/v_cur. The concat and the round-trip are deleted (+25 / −19 vs 49ad6bc, including the test). Measuredtest-walk-exact, qwen2.5-0.5b q4_k_m, M5 Metal, live step vs the walk's exact step:
One FAILED line is unchanged and pre-existing on base 5e41634: "a refused chunk graph was not retried cleanly at a smaller horizon". Real Qwen3.6-35B-A3B Q4_K_M, live engine flags (q4_0,
Adapters: 40/40 tensors change from the original in both builds. Base vs head differ in hashes, but the 400 sampled values match (max |diff| 0). 🤖 Generated with Claude Code |
The live
/learnstep built its backward through the whole stream's K/V cache view. That made one f32 [512, 676864] gradient (1322 MiB) per K and V on each of the 10 full-attention layers, and the preflight sized its lease from that.Commits (separately reviewable, per Codex's order):
llama_learn_step_plan: her rows, the same object for the preflight and the live step. It changes no graph.k_cur/v_cur. Without this, (2) is refused on a q4_0 cache: "no backward through GET_ROWS ... neither F32 nor F16".Measured
Real Qwen3.6-35B-A3B Q4_K_M on the M5 with the live engine's flags (
-c 676715 --kv-unified, q4_0 K/V, flash attention), real resident examples, serving down, 2026-11-18 14:05–14:09Z. Figure:/learn/preflightshared_compute_requiredon MTL0. 4.40 GB of each figure is serving's already-held arena.test-learn-step-plan: ok.Not yet measured (blocks the pin bump)
/learnstep: loss, gradients and updates vs the old path, including adapters and after a swap.n_kv≤ planned; neither invariant assert fires on the chunked path.Open for review
PersonaUnit'sLearningpart, a view over herBlocksincontinuum-persona-engine(DeepSeek VL support ggml-org/llama.cpp#6130), rather than a cell lookup in a shared stream. That is the follow-up on the core side.🤖 Generated with Claude Code
https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo